package com.sanpu.kxe.business.main.adapter;

import android.text.TextUtils;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sanpu.kxe.R;
import com.sanpu.kxe.business.main.bean.AdviceOutput;

import java.util.ArrayList;

/**
 * Description：了难咨询
 * Created by 薛勇军 on 2019/3/12.
 */

public class AdviceListAdapter extends BaseQuickAdapter<AdviceOutput, BaseViewHolder> {

    public AdviceListAdapter() {
        super(R.layout.item_advice_list, new ArrayList<AdviceOutput>());
    }

    @Override
    protected void convert(BaseViewHolder helper, AdviceOutput item) {
        if (item != null) {
            helper.setText(R.id.timeTv,
                    TextUtils.isEmpty(item.getReleaseDate())?"":item.getReleaseDate())
                    .setText(R.id.adviceTypeTv, getTitleByType(item.getTaskType()))
                    .setText(R.id.desTv,
                            TextUtils.isEmpty(item.getTaskDescription())?"":item.getTaskDescription())
                    .setText(R.id.statusTv, getTitleByStatus(item.getTaskStatus()));
            View topLineView = helper.getView(R.id.topLineView);
            try {
                AdviceOutput output = getItem(0);
                if (output != null && TextUtils.equals(item.getTaskId(), output.getTaskId())) {
                    topLineView.setVisibility(View.VISIBLE);
                } else {
                    topLineView.setVisibility(View.GONE);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static String getTitleByType(String type) {
        if (TextUtils.isEmpty(type)) return "";
        switch (type) {
            case "LEGAL_ACTION":
                return "法律诉讼";
            case "PUBLIC_RELATIONS":
                return "公众关系";
            case "CREDIT_LOANS":
                return "信用贷款";
            case "DEBT_COLLECTION":
                return "债务催收";
            case "OTHER":
                return "其他";
            default:
                return "";
        }
    }

    public static String getTitleByStatus(String status) {
        if (TextUtils.isEmpty(status)) return "";
        switch (status) {
            case "WATING":
                return "待处理";
            case "PROCESSING":
                return "处理中";
            case "SUCCESS":
                return "成功";
            case "CLOSED":
                return "已关闭";
            default:
                return "";
        }
    }
}
